<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles-extras" prefix="tilesx" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="security"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="tag"%>

<script type="text/javascript">

$(document).ready(function()
{
});

function openSaveChangesDialog()
{
  afterFieldEdit('<spring:message code="field.name"/>', 'string', 'supportedMapID.name', 'false', new Array());
  setTimeout("checkErrorsForSaveChangesDialog()", 100);
}

function enableSave()
{
  if ($(parseIdForJQuery("supportedMapID.name")).val() != '')
  {
    var saveButton = $("#saveButton");
    saveButton.click(function() {openSaveChangesDialog();});
    saveButton.mouseover(function () {buttonHover(this);});
    saveButton.mouseout(function() {buttonNormal(this);});
    saveButton.addClass("button_input").removeClass("button_inputDisabled");
  }
}

function updateChange()
{
	  if (changeCountField != null)
	  {
	    changeCountField.value = parseInt(changeCountField.value) + 1;
	    checkButtons(changeCountField.value);
	  }
}

function activateDeactivate()
{
	var isActive = $("#adminCommand\\.supportedMapID\\.active").val();
	var htmlToInsert;

	if (isActive == 'true')
	{
		$("#adminCommand\\.supportedMapID\\.active").val(false);

		htmlToInsert = "<tr>"
                     + "<td style='border-style:none;border-width:0px;border-color:white;font-size:14px;background-color:#ffff97'>"
                     + "Disabling Supported MAP</td>"
                     + "</tr>";
	}
	else
	{
		$("#adminCommand\\.supportedMapID\\.active").val(true);

		htmlToInsert = "<tr>"
                     + "<td style='border-style:none;border-width:0px;border-color:white;font-size:14px;background-color:#ffff97'>"
                     + "Enabling Supported MAP</td>"
                     + "</tr>";
	}

	$("#activateDeactivateTable").html(htmlToInsert);
	$("#activateDeactivateTable").css('backgroundColor', '#ffff97');
	$("#activateDeactivateTd").css('backgroundColor', '#ffff97');

  var changeCountField = document.getElementById('changeCount');
  if (changeCountField != null)
  {
    changeCountField.value = parseInt(changeCountField.value) + 1;
    checkButtons(changeCountField.value);
  }
}
</script>

<form id="adminForm" name="adminForm" method="post">

  <form:hidden path="adminCommand.adminRequestedAction" id="adminCommand.adminRequestedAction"/>
  <form:hidden path="adminCommand.isNew" id="adminCommand.isNew"/>
  <form:hidden path="adminCommand.supportedMapID.active" id="adminCommand.supportedMapID.active"/>
  <form:hidden path="adminCommand.supportedMapID.pk" id="adminCommand.supportedMapID.pk"/>
  <input type="hidden" id="callStatus" name="callStatus" value=""/>
  <tag:errors name="adminCommand"/>

  <table>
    <jsp:include page="/pages/jsp/tiles/admin/errors.jsp"/>
  </table>

  <table align="center">
    <tr>
      <td>
        <table class="adminEdit" align="center">
          <tr>
            <th align="center" width="200px"><spring:message code="field.name"/></th>
            <security:authorize ifAllGranted="ROLE_EDITABLE">
            <spring:bind path="adminCommand.supportedMapID.name">
            <td width="400px">
              <input type="hidden" id="${status.expression}_originalValue" name="${status.expression}_originalValue" value="${status.value}"/>
              <input type="text" id="${status.expression}" name="${status.expression}" value="${status.value}" tabindex="1"
                     class="largeTextField" maxlength="30"
                     onkeyup="fieldEdit('${status.expression}');"
                     onchange="afterFieldEdit('<spring:message code="field.name"/>', 'string', '${status.expression}', 'false', new Array());"/>&nbsp;*
              <div id="${status.expression}_errorField" class="errorText" style="visibility:hidden;display:none;"></div>
            </td>
            </spring:bind>
            </security:authorize>
            <security:authorize ifNotGranted="ROLE_EDITABLE">
            <td width="400px">${adminCommand.supportedMapID.name}</td>
            </security:authorize>
          </tr>

          <tr>
            <th><spring:message code="field.active"/></th>
            <security:authorize ifAllGranted="ROLE_EDITABLE">
            <td id="activateDeactivateTd">
              <c:choose>
              <c:when test="${adminCommand.supportedMapID.active}">
              <table align="center" id="activateDeactivateTable">
                <tr>
                  <td style="border-style:none;border-width:0px;border-color:white;font-size:14px">Supplier MAP ID is active</td>
                  <td style="border-style:none;border-width:0px;border-color:white;">
                  <a id="activateDeactivateButton"
                     class="button_input" style="width:90px;min-width:90px;max-width:90px"
                     onclick="activateDeactivate();" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);">
                    <span><spring:message code="button.deactivate"/></span>
                  </a>
                  </td>
                </tr>
              </table>
              </c:when>
              <c:otherwise>
              <table align="center" id="activateDeactivateTable">
                <tr>
                  <td style="border-style:none;border-width:0px;border-color:white;font-size:14px">Supplier MAP ID is not active</td>
                  <td style="border-style:none;border-width:0px;border-color:white;">
                  <a id="activateDeactivateButton"
                     class="button_input" style="width:90px;min-width:90px;max-width:90px"
                     onclick="activateDeactivate();" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);">
                    <span><spring:message code="button.activate"/></span>
                  </a>
                  </td>
                </tr>
              </table>
              </c:otherwise>
              </c:choose>
            </td>
            </security:authorize>
            <security:authorize ifNotGranted="ROLE_EDITABLE">
            <c:choose>
            <c:when test="${adminCommand.supportedMapID.active}">
            <td>Supported MAP is active</td>
            </c:when>
            <c:otherwise>
            <td>Supported MAP is not active</td>
            </c:otherwise>
            </c:choose>
            </security:authorize>
          </tr>
        </table>
      </td>
    </tr>

    <tr>
      <td>
        <table align="center" style="margin-top:10px;">
          <tr>
            <td style="text-align: center;"><jsp:include page="/pages/jsp/tiles/admin/supportedMapEditButtons.jsp"/></td>
          </tr>
        </table>
      </td>
    </tr>

    <jsp:include page="/pages/jsp/tiles/admin/hoverConfirmation.jsp"/>

  </table>

</form>

